package cn.wolfcode.controller;

//在推
import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result getDepts() {
        return Result.success(deptService.getAll());
    }

    @DeleteMapping("/{id}")
    public Result deleteDept(@PathVariable long id) {
        deptService.delById(id);
        return Result.success();
    }

    @PostMapping
    public Result addDept(@RequestBody Dept dept) {
        deptService.add(dept);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getDept(@PathVariable long id) {
        return Result.success(deptService.getById(id));
    }
    @PutMapping
    public Result updateDept(@RequestBody Dept dept) {
        deptService.update(dept);
        return Result.success();
    }
}
